<template>
  <div class="detail">
    <el-card>
      <el-button class="print" type="primary" @click="print">打印</el-button>
      <el-tabs v-model="activeName">
        <el-tab-pane label="登陆账户设置" name="first">
          <el-form class="myform" :model="form" label-width="70px">
            <el-form-item label="姓名">
              <el-input v-model="form.username"></el-input> </el-form-item
            ><el-form-item label="密码">
              <el-input v-model="form.password" type="password"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="update">更新</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情" name="second"
          ><userInfo></userInfo
        ></el-tab-pane>
        <el-tab-pane label="岗位信息" name="third">岗位信息</el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { getEmployeesApi, setEmployeesApi } from '@/api/Employees'
export default {
  data () {
    return {
      activeName: 'first',
      form: {
        username: '',
        password: ''
      },
      id: this.$route.params.id
    }
  },
  components: {
    userInfo: () => import('../components/user-info.vue')
  },
  methods: {
    async getEmployees () {
      const res = await getEmployeesApi(this.id)
      this.form = { ...res.data }
    },
    async update () {
      await setEmployeesApi(this.form)
      this.$message.success('修改成功')
      this.$router.push('/employees')
    },
    print () {
      let type =
        this.activeName == 'first' || this.activeName == 'second'
          ? 'first'
          : 'second'
      console.log(this.id)
      console.log(type)
      this.$router.push(`/employees/print/${this.id}?type=${type}`)
    }
  },
  created () {
    this.getEmployees()
  }
}
</script>

<style lang="scss" scoped>
.detail {
  position: relative;
  margin: 20px;
  .myform {
    width: 40%;
    margin: 40px 0px 0px 260px;
  }
  .print {
    position: absolute;
    right: 20px;
    top: 10px;
  }
}
</style>
